package com.wander.business.book.c2_2_2.config;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.Resource;


/**
 * @author Wander.Zeng
 * @create 2017-08-13 09:54
 * @desc BookConfig_c2_2_2
 */
@Configuration
@ComponentScan("com.wander.business.book.c2_2_2")
//@PropertySource("classpath:com/wander/business/book/c2_2_2/config/test.properties")
public class BookConfig_c2_2_2 {

    @Value("normal wander")
    private String normal;
    @Value("#{systemProperties['os.name']}")
    private String osName;
    @Value("#{ T(java.lang.Math).random() * 100.0}")
    private double randomNumber;
    @Value("#{demoService.another}")
    private String fromAnother;
    //@Value("classpath:src/main/java/com/wander/business/book/c2_2_2/config/test.txt")
    //private Resource testFile;
    @Value("http://www.baidu.com")
    private Resource testUrl;
    //@Value("${book.name}")
    //private String bookName;
    //@Autowired
    //private Environment environment;

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    public void outputResource() {
        try {
            System.out.println(normal);
            System.out.println(osName);
            System.out.println(randomNumber);
            System.out.println(fromAnother);
            //System.out.println(IOUtils.toString(testFile.getInputStream()));
            System.out.println(IOUtils.toString(testUrl.getInputStream()));
            //System.out.println(bookName);
            //System.out.println(environment.getProperty("book.author"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
